home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / FileM.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  2.9 KB  |  139 lines  |  [TEXT/KAHL]

  1. /* FileM.c */    /*    C14 Calculator */
  2.  
  3. #include "ResourceDefs.h"
  4. #include "Miscellany.h"
  5. #include "Globals.h"
  6. #include "FileM.h"
  7. #include "Dispatcher.h"
  8. #include "PredatorPreyData.h"
  9. #include "calc_wizard.h"
  10.  
  11. /*static void        CloseAppWindow    (void);*/
  12. static void        DoSave (void);
  13. static void        DoSaveAs (void);
  14.  
  15.  
  16. void    FileMSeg()    {}
  17.  
  18.  
  19. /*----------*/
  20. static void DoSaveAs (void)
  21. {
  22.     SFReply            sfInfo;
  23.     short            fRefNum;
  24.     StringHandle    prompt;
  25.     Str255            promptStr;
  26.     Str255            suggestion;
  27.  
  28.     prompt = GetString (SaveAsPromptID);
  29.     if (prompt != nil) {
  30.         BlockMove (&(**prompt), promptStr, GetHandleSize ((Handle) prompt));
  31.     } else {
  32.         promptStr [0] = 0;
  33.     }
  34.     BlockMove (&(**cur->filename), suggestion, GetHandleSize ((Handle) cur->filename));
  35.  
  36.     if (CreateFile (&sfInfo, promptStr, suggestion, kSignature, kFileType)) {
  37.         CloseAppFile (cur->fileNum);
  38.         if (OpenAppFile (sfInfo.vRefNum, sfInfo.fName, &fRefNum)) {
  39.             SetWTitle (curWindow, sfInfo.fName);
  40.             cur->fileNum = fRefNum;
  41.             cur->volNum = sfInfo.vRefNum;
  42.             SetString (cur->filename, sfInfo.fName);
  43.             WriteAppFile (2,cur->fileNum);
  44.             cur->dirty = false;
  45.         } else { /*should never happen*/
  46.             SetWTitle (curWindow, "\p???");
  47.             cur->fileNum = 0;
  48.             cur->volNum = 0;
  49.         }
  50.     }
  51. } /*DoSaveAs*/
  52.  
  53. /*----------*/
  54. static void DoSave (void)
  55. {
  56.     if (cur->fileNum == 0) {
  57.         DoSaveAs ();
  58.     } else {
  59.         WriteAppFile (2,cur->fileNum);
  60.         cur->dirty = false;
  61.     }
  62. } /*DoSave*/
  63.  
  64.  
  65. /*----------*/
  66. /*static void CloseAppWindow (void)*/
  67. /*{*/
  68. /*    enum {saveItem = 1, cancelItem, discardItem};*/
  69. /**/
  70. /*    Str255            curTitle;*/
  71. /*    short            itemNum;*/
  72. /*    Boolean            okay;*/
  73. /**/
  74. /*    okay = true;*/
  75. /*    SetInfo (FrontWindow ());*/
  76. /*    if (cur->dirty) {*/
  77. /*        GetWTitle (curWindow, curTitle);*/
  78. /*        ParamText (curTitle, "\p", "\p", "\p");*/
  79. /*        InitCursor ();*/
  80. /*        itemNum = Alert (SaveID, nil);*/
  81. /*        switch (itemNum) {*/
  82. /*            case saveItem:*/
  83. /*                    DoSave ();*/
  84. /*                    okay = !errorFlag;*/
  85. /*                break;*/
  86. /*            case discardItem:*/
  87. /*                   /*Do nothing»;*/
  88. /*                break;*/
  89. /*            case cancelItem:*/
  90. /*                    errorFlag = true;*/
  91. /*                    okay = false;*/
  92. /*                break;*/
  93. /*        } /*switch»*/
  94. /*    }*/
  95. /*    if (okay) {*/
  96. /*        DisposeAppData ();*/
  97. /*        if (cur->windowKind == 1) {        /* 1st or only window in set »*/
  98. /*            CloseAppFile (cur->fileNum);*/
  99. /*        }*/
  100. /*        CloseCurWindow ();*/
  101. /*    }*/
  102. /*}*/ /*CloseAppWindow*/
  103.  
  104. /*----------*/
  105. void DoClose (void)
  106. {
  107.     WindowPeek        frontPeek;
  108.  
  109.     errorFlag = false;
  110.  
  111.     frontPeek = (WindowPeek) FrontWindow ();
  112.     if (frontPeek->windowKind < 0) {
  113.         CloseDeskAcc (frontPeek->windowKind);
  114.     } else if (frontPeek->windowKind == dialogKind) {
  115.         CloseModelessDialog (FrontWindow ());
  116.     }/* else {*/
  117. /*        CloseAppWindow ();*/
  118. /*    }*/
  119. } /*DoClose*/
  120.  
  121.  
  122. /*----------*/
  123. void DoQuit (void)
  124. {
  125.     Boolean            quitting;
  126.  
  127.     quitting = true;
  128.     while (quitting && (FrontWindow () != nil)) {
  129.         SystemTask ();
  130.         DoClose ();
  131.         if (errorFlag) {
  132.             quitting = false;
  133.         }
  134.     } /*while*/
  135.  
  136.     if (quitting) {
  137.         quittingTime = true;
  138.     }
  139. } /*DoQuit*/